﻿using Microsoft.AspNetCore.Mvc;
using VisionCloud.Domain.Common;

namespace VisionSurface.Web.Controllers
{
    [ApiController]
    public class ApiBaseController : Controller
    {
        /// <summary>
        /// 登录token(增加此Header是为了方便在swagger文档调试接口)
        /// </summary>
        [FromHeader(Name = "Authorization")]
        public string Token { get; set; }

        /// <summary>
        /// Token中的用户信息
        /// </summary>
        public OperatorInfo TokenModel { get; set; } = OperatorProvider.Get();

        /// <summary>
        /// 获取接口名称
        /// </summary>
        /// <param name="parms"></param>
        /// <returns></returns>
        [NonAction]
        public string GetOpenApiName(params object[] parms)
        {
            if (parms != null && parms.Length > 0)
            {
                return ControllerContext.HttpContext.Request.Path
                       + ControllerContext.HttpContext.Request.QueryString
                       + string.Join(',', parms);
            }
            return ControllerContext.HttpContext.Request.Path + ControllerContext.HttpContext.Request.QueryString;
        }
    }
}
